<!--
 * @Author: 汪军 624473119@qq.com
 * @Date: 2023-10-22 13:13:43
 * @LastEditors: 汪军 624473119@qq.com
 * @LastEditTime: 2023-10-30 11:38:43
 * @FilePath: \app-formwork\src\pages\login\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template lang="pug">
view.edit-password
  view.px-32.py-60
    u--form(
      labelPosition="top",
      :model="form",
      :rules="rules",
      labelWidth="auto",
      :labelStyle="labelStyle",
      ref="formRef"
    )
      u-form-item(label="请输入您的旧密码：", prop="form.oldpassword", :borderBottom="true", ref="item1")
        u--input(v-model="form.oldpassword", placeholder="请输入", border="none")
      u-form-item(label="输入新密码：", prop="form.password", :borderBottom="true", ref="item1")
        u--input(v-model="form.password", placeholder="请输入", border="none")
      u-form-item(label="确认您的新密码：", prop="form.quepassword", :borderBottom="true", ref="item1")
        u--input(v-model="form.quepassword", placeholder="请输入", border="none")
  view.btn-group.px-32
    up-button.btn(type="primary", text="确定修改", shape="circle", @click="queRedit")
</template>

<script setup>
import { userApi } from "../../api";
const formRef = ref();
const rules = ref({
  oldpassword: [{ required: true, message: "请输入旧密码", trigger: "blur" }],
  password: [{ required: true, message: "请输入新密码", trigger: "blur" }],
  quepassword: [{ required: true, message: "请再次输入新密码", trigger: "blur" }]
});
const form = ref({
  oldpassword: "",
  password: "",
  quepassword: ""
});
const labelStyle = ref({
  fontSize: "16px",
  fontWeight: "bold",
  marginBottom: "16px"
});
//确认修改
const queRedit = () => {
  
  userApi
    .changepwd(form.value)
    .then((res) => {
      if (res.code == 1) {
        console.log("res", res.msg);
        uni.showToast({ title: res.msg, icon: "none" });
        //去登录页
        uni.navigateTo({ url: "/pages/login/index" });
      }
      if (res.code == 0) {
        uni.showToast({ title: res.msg, icon: "none" });
      }
    })
    .catch((err) => {
      console.log('err',err);
    });
  
  // uni.showToast({ title: err.msg, icon: "none" });
};
</script>

<style lang="stylus" scoped>
.edit-password {
  .btn-group {
    position: fixed;
    width: 100%;
    bottom: 40rpx;
    box-sizing: border-box;

    .btn {
      background: #306EFF;
      height: 44px;
    }
  }
}
</style>
